package com.peng.mapper;

import com.peng.pojo.Group;
import com.peng.pojo.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.sql.Date;
import java.util.List;

@Mapper
@Repository
public interface GroupChatMapper {
    /**
     * 群组列表查询
     *
     * @param name 群名称
     * @param time 创建时间
     * @return
     */
    List<Group> selectAllGroup(@Param("name") String name, @Param("time") Date time);

    /**
     * 查询群组总人数
     *
     * @param groupId
     * @return
     */
    @Select("select count(*) from tb_group_user where group_id = #{groupId}")
    int selectGroupTotalPerson(int groupId);

    /**
     * 查询群组管理员人数
     *
     * @param groupId
     * @return
     */
    @Select("select count(*) from tb_group_user where group_id = #{groupId} and state = 1")
    int selectGroupTotalManagerPerson(@Param("groupId") int groupId);

    @Select("select nick_name,real_name from tb_user where id = #{id}")
    User selectUserById(int id);

    /**
     * 修改群组状态
     *
     * @param status 1为正常，2为冷冻，3为关闭
     * @param id
     * @return
     */
    int updateGroupStatus(@Param("status") int status, @Param("id") Integer... id);
}
